package com.chain.qs.modules.biz.service;

import com.chain.qs.common.service.CrudService;
import com.chain.qs.modules.biz.dao.EquipmentDao;
import com.chain.qs.modules.biz.entity.Equipment;
import com.chain.qs.modules.biz.entity.EquipmentGroupItem;
import com.chain.qs.modules.biz.entity.EquipmentParameter;
import com.chain.qs.modules.biz.entity.EventTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * 设备Service
 *
 * @author wangzhiping
 */
@Service
//@Transactional(readOnly = true)
public class EquipmentService extends CrudService<EquipmentDao, Equipment> {
    @Resource
    private EquipmentGroupItemService equipmentGroupItemService;
    @Resource
    private EquipmentParameterService equipmentParameterService;
    @Resource
    private EventTemplateService eventTemplateService;

    public Equipment getByKid(Equipment entity) {
        return dao.getByKid(entity);
    }

    public String etypeKid(String itemId) {
        return dao.etypeKid(itemId);
    }

    public void delete(Equipment entity) {
        for (EquipmentGroupItem equipmentGroupItem : equipmentGroupItemService.findListByEquId(entity.getId())) {
            equipmentGroupItemService.delete(equipmentGroupItem);
        }
        for (EquipmentParameter equipmentParameter : equipmentParameterService.paramList(entity.getId())) {
            equipmentParameterService.delete(equipmentParameter);
        }
        for (EventTemplate eventTemplate : eventTemplateService.findListByEquipId(entity.getId())) {
            eventTemplateService.delete(eventTemplate);
        }
        super.delete(entity);
    }
}
